package com.zf.shuashua.advert.mg;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.PhoneUtils;
import com.zf.shuashua.net.ApiConstant;

public class MangoUtils {

    public static boolean actionDeepLink(Activity activity, String deepLink) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(deepLink));
//        intent.setData(Uri.parse("iqiyi://mobile/home?ftype=27&subtype=314"));
        if (intent.resolveActivity(activity.getPackageManager()) != null) {
//            MLog.logd("启动成功");
            activity.startActivity(intent);
            return true;
        } else {
//            MLog.logd("跳转DeepLink失败");
            return false;
        }
    }

    /**
     * //网络连接类型 0 - 无法探测 1 - 蜂窝数据接入，未知网络类型 2 - 蜂窝数据 2G 网络 3 - 蜂窝数据 3G 网络 4 - 蜂窝数据 4G 网络 5 - 蜂窝数据 5G 网络 6 - LTE 网络 100 - Wi-Fi 网络接入 101 - 以太网接入
     */
    public static int getConnectionType() {
        NetworkUtils.NetworkType networkType = NetworkUtils.getNetworkType();
        if (networkType == NetworkUtils.NetworkType.NETWORK_2G) {
            return 2;
        } else if (networkType == NetworkUtils.NetworkType.NETWORK_3G) {
            return 3;
        } else if (networkType == NetworkUtils.NetworkType.NETWORK_4G) {
            return 4;
        } else if (networkType == NetworkUtils.NetworkType.NETWORK_ETHERNET) {
            return 101;
        } else if (networkType == NetworkUtils.NetworkType.NETWORK_WIFI) {
            return 100;
        } else if (networkType == NetworkUtils.NetworkType.NETWORK_UNKNOWN) {
            return 2;
        } else {
            return 0;
        }
    }

    public static int getOperator() {
        String operatorName = PhoneUtils.getSimOperatorByMnc();
        if ("中国移动".equals(operatorName)) {
            return 1;
        } else if ("中国联通".equals(operatorName)) {
            return 3;
        } else if ("中国电信".equals(operatorName)) {
            return 2;
        } else {
            return 0;
        }
    }

    public static String getBaseUrl() {
//        AdConfigBean sdkConfig = SpKit.getSDKConfig();
        String baseUrl = ApiConstant.baseUrl;
//        if (sdkConfig != null) {
//            for (ConfigBean.SDKBean item : sdkConfig.getSdks()) {
//                if (SDKType.MANGO.getType() == item.getType()) {
//                    baseUrl = item.getRequestUrl();
//                }
//            }
//        }
        return baseUrl;
    }
}
